﻿using System.Collections.Generic;
using System.Linq;
using System.Collections.ObjectModel;
using Startup.Shell.Domain;
using Startup.Shell.ModelDesignerPreview;
using Startup.Shell.Modules.PreviewDesignerHierarchyModule;

namespace Startup.Shell.Modules.WindowDesignerModule
{
	public class WindowDesignerViewModel
	{
		private readonly WindowDesignerModel _model;

		public WindowDesignerViewModel(WindowDesignerModel model)
		{
			_model = model;
		}

		public static WindowDesignerViewModel Designer
		{
			get
			{
				var domainClass = new StartupClass { Name = "DomainModel" };
				domainClass.Properties.Add(new StartupProperty { Name = "Id", Type = "Guid"} );
				domainClass.Properties.Add(new StartupProperty { Name = "Name", Type = "string"} );
				domainClass.Properties.Add(new StartupProperty { Name = "Description", Type = "string"} );

				PreviewContainer reviewContainer = new PreviewContainer { Preview = new WindowDesignerPreview() };

				StartupProject project = new StartupProject();
				project.Classes.Add(new StartupDomainModelClass());
				project.MainWindow = reviewContainer;

				var model = new WindowDesignerModel(project);
				return new WindowDesignerViewModel(model);
			}
		}

		public IList<StartupProperty> DomainProperties
		{
			get { return _model.DomainClass.AllProperties.Concat(_model.StartupProject.Classes.SelectMany(x => x.AllProperties)).ToArray(); }
		}

		public PreviewDesignerHierarchyViewModel MainWindowViewModel
		{
			get { return new PreviewDesignerHierarchyViewModel(_model.StartupProject, _model.MainWindow, _model.DomainClass); }
		}
	}
}
